static char*
ce_gen_creation_time(time_t tm)
{
- xml_fill_in_time(time_buffer, tm, XML_SHORT_TIME);
+ QDateTime qtm;
+ qtm = QDateTime::fromTime_t(tm);
+ xml_fill_in_time(time_buffer, qtm, XML_SHORT_TIME);
return time_buffer;
}
is_available(status_unknown),
is_memberonly(status_unknown),
has_customcoords(status_unknown),
- exported(0),
last_found(0),
placer_id(0),
favorite_points(0)
status_type is_available:2;
status_type is_memberonly:2;
status_type has_customcoords:2;
- time_t exported;
+ gpsbabel::DateTime exported;
time_t last_found;
QString placer; /* Placer name */
int placer_id; /* Placer id */
QString icon_descr;
gpsbabel::DateTime GetCreationTime() const {
-//QDateTime dt(creation_time);
-//qDebug() << dt.toString("dd.MM.yyyy hh:mm:ss.zzz");
-//fprintf(stderr, "ng %d\n", (int)creation_time);
return creation_time;
-}
+ }
void SetCreationTime(gpsbabel::DateTime t) { creation_time = t;
-//qDebug() << t.toString("dd.MM.yyyy hh:mm:ss.zzz");
-//fprintf(stderr, "ns %d\n", (int)t);
-}
+ }
void SetCreationTime(time_t t) { creation_time = t;
-//fprintf(stderr, "t %d\n", (int)t);
-}
+ }
void SetCreationTime(time_t t, int us) {
creation_time = t;
microseconds = us;
-//fprintf(stderr, "t/us %d %d\n", (int)t, us);
}
gpsbabel::DateTime creation_time;
int microseconds; /* Optional millionths of a second. */
double avg_hrt; /* Avg Heartrate */
double avg_cad; /* Avg Cadence */
time_t start; /* Min time */
- time_t end; /* Max time */
+ time_t end; /* Max time */
int min_hrt; /* Min Heartrate */
int max_hrt; /* Max Heartrate */
int max_cad; /* Max Cadence */
signed int get_tz_offset(void);
time_t mklocaltime(struct tm* t);
time_t mkgmtime(struct tm* t);
-time_t current_time(void);
+gpsbabel::DateTime current_time(void);
void dotnet_time_to_time_t(double dotnet, time_t* t, int* ms);
signed int month_lookup(const char* m);
const char* get_cache_icon(const waypoint* waypointp);
+++ /dev/null
-// Copyright ME.
-
-#include <QDateTime>
-
-// As this code began in C, we have several hundred places that set and
-// read creation_time as a time_t. Provide some operator overloads to make
-// that less painful.
-class gbDateTime : public QDateTime {
-public:
- operator const time_t() const {
- return this->toTime_t();
- }
- const time_t& operator=(const time_t& t) {
- this->setTime_t(t);
- }
-};
-
-
}
gbfprintf(ofd, " </Position>\n");
gbfprintf(ofd, " ");
- xml_write_time(ofd, wpt->GetCreationTime(), wpt->microseconds, "Time");
+ QDateTime dt = wpt->GetCreationTime();
+ xml_write_time(ofd, dt, "Time");
gbfprintf(ofd, " </Trackpoint>\n");
}
static void
gpx_write(void)
{
- time_t now = 0;
-
/* if an output version is not specified and an input version is
* available use it, otherwise use the default.
*/
gpx_write_gdata(&gpx_global->urlname, "urlname");
}
- now = current_time();
+ gpsbabel::DateTime now = current_time();
char time_string[64];
xml_fill_in_time(time_string, now, XML_LONG_TIME);
if (time_string[0]) {
static int gtc_sport = 0;
static int gtc_course_flag;
-static time_t gtc_least_time;
-static time_t gtc_most_time;
+static gpsbabel::DateTime gtc_least_time;
+static gpsbabel::DateTime gtc_most_time;
static double gtc_start_lat;
static double gtc_start_long;
static double gtc_end_lat;
}
if (td->start && td->end) {
char time_string[64];
-
- xml_fill_in_time(time_string, td->start, XML_LONG_TIME);
+ // FIXME (robertl): this straddling of time and string types is killing me
+ xml_fill_in_time(time_string, QDateTime::fromTime_t(td->start), XML_LONG_TIME);
kml_td(hwriter, "Start Time", QString(" %1 ").arg(time_string));
- xml_fill_in_time(time_string, td->end, XML_LONG_TIME);
+ xml_fill_in_time(time_string, QDateTime::fromTime_t(td->end), XML_LONG_TIME);
kml_td(hwriter, "End Time", QString(" %1 ").arg(time_string));
}
if (td->start && td->end) {
char time_string[64];
writer->writeStartElement("TimeSpan");
- xml_fill_in_time(time_string, td->start, XML_LONG_TIME);
+ // FIXME (robertl): this straddling of time and string types is gross
+ xml_fill_in_time(time_string, QDateTime::fromTime_t(td->start), XML_LONG_TIME);
writer->writeTextElement("begin", time_string);
- xml_fill_in_time(time_string, td->end, XML_LONG_TIME);
+ xml_fill_in_time(time_string, QDateTime::fromTime_t(td->end), XML_LONG_TIME);
writer->writeTextElement("end", time_string);
writer->writeEndElement(); // Close TimeSpan tag
}
}
if (kml_time_max) {
char time_string[64];
- time_t time_max;
+ gpsbabel::DateTime time_max;
// In realtime tracking mode, we fudge the end time by a few minutes
// to ensure that the freshest data (our current location) is contained
// within the timespan. Earth's time may not match the GPS because
tdata->max_alt = unknown_alt;
QUEUE_FOR_EACH((queue *)&trk->waypoint_list, elem, tmp) {
- time_t timed;
+ gpsbabel::DateTime timed;
double tlat, tlon, plat, plon, dist;
thisw = (waypoint *)elem;
}
/*
- * A wrapper for time(2) that allows us to "freeze" time for testing.
+ * Historically, when we were C, this was A wrapper for time(2) that
+ * allowed us to "freeze" time for testing. The UNIX epoch
+ * (1970-1-1-00:00:00UTC) was a convenient value for that. Now in the
+ * world of Qt, sub-second time is convenient, but regenerating all the
+ * reference files would be tedious, so we uphold that convention.
*/
-time_t
+gpsbabel::DateTime
current_time(void)
{
if (getenv("GPSBABEL_FREEZE_TIME")) {
- return 0;
+ return QDateTime::fromTime_t(0);
}
- return time(NULL);
+ return QDateTime::currentDateTime();
}
/*
}
void
-xml_fill_in_time(char *time_string, const time_t timep, int long_or_short)
+xml_fill_in_time(char *time_string, const gpsbabel::DateTime datetime, int long_or_short)
{
- QDateTime dt = QDateTime::fromTime_t(timep);
+ QDateTime dt = datetime;
dt = dt.toUTC();
const char* format;
}
void
-xml_write_time(gbfile *ofd, const time_t timep, int microseconds, const char *elname)
+xml_write_time(gbfile *ofd, gpsbabel::DateTime dt, const char *elname)
{
char time_string[64];
- xml_fill_in_time(time_string, timep, XML_LONG_TIME);
+ xml_fill_in_time(time_string, dt, XML_LONG_TIME);
if (time_string[0]) {
gbfprintf(ofd, "<%s>%s</%s>\n",
elname,
void write_optional_xml_entity(gbfile* ofd, const QString& indent,
const QString& tag, const QString& value);
-void xml_write_time(gbfile* ofd, const time_t timep, int microseconds, const char* elname);
-void xml_fill_in_time(char* time_string, const time_t timep, int long_or_short);
+void xml_write_time(gbfile* ofd, gpsbabel::DateTime time, const char* elname);
+void xml_fill_in_time(char* time_string, const gpsbabel::DateTime timep, int long_or_short);
void write_xml_header(gbfile* ofd);
void xml_ignore_tags(const char** taglist);